package com.yxw.springmvc.userBehavior.Exception;

import lombok.Getter;

/**
 * Created by hp on 2016/9/23.
 */
public class ServiceException extends RuntimeException {
    /**
     * 错误描述
     */
    @Getter
    private String errorMsg;

    /**
     * 错误码
     */
    @Getter
    private String errorCode;

    public ServiceException(String errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public ServiceException(ErrorDef transResCode) {
        this.errorCode = transResCode.getCode();
        this.errorMsg = transResCode.getDesc();
    }

    public ServiceException(ErrorDef transResCode, Object... params) {
        this.errorCode = transResCode.getCode();
        this.errorMsg = String.format(transResCode.getDesc(), params);
    }


    @Override
    public String getMessage() {
        return String.format("[%s]%s.", getErrorCode(), getErrorMsg());
    }
}
